package com.design.strategy.shallow;

import lombok.Data;

import java.util.List;
/**
 * 浅克隆：创建一个新对象，新对象的属性和原来对象完全相同，对于非基本类型属性，仍指向原有属性所指向的对象的内存地址。
 * @Author:         cong zhi
 * @CreateDate:     2021/3/20 17:42
 * @UpdateUser:     cong zhi
 * @UpdateDate:     2021/3/20 17:42
 * @UpdateRemark:   修改内容
 * @Version:        1.0
 */
@Data
public class ConcretePrototype implements Cloneable {

    private int age;
    private String name;


    private List<String> hobbies;

    public List<String> getHobbies() {
        return hobbies;
    }


    @Override
    public ConcretePrototype clone() {
        try {
            // clone 对象
            return (ConcretePrototype) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public String toString() {
        return "ConcretePrototype{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", hobbies=" + hobbies +
                '}';
    }
}
